<template>
    <mi-form-page @submit="submit" v-loading="edit.loading">
        <el-form :model="edit.info"
                 :rules="rules"
                 ref="formRef">

            <el-form-item prop="title" label="名称">
                <mi-input v-model="edit.info.title"/>
            </el-form-item>
            <el-form-item prop="desc" label="描述">
                <mi-input v-model="edit.info.desc" type="textarea" :rows="3" />
            </el-form-item>
            <el-form-item prop="rules" label="权限">
<!--                <mi-input v-model="edit.info.rules" />-->

                <mi-check-tree v-model="edit.info.rules" url="/site.siteRule/options" />
            </el-form-item>


<!--            <el-form-item prop="status" label="状态">-->
<!--                <mi-switch v-model="edit.info.status"/>-->
<!--            </el-form-item>-->

        </el-form>
    </mi-form-page>

</template>

<script setup lang="ts">
import {ref, onBeforeMount, inject} from "vue";
import {simpleGet} from "@/utils/request";
import {makeModelAuth} from "@/utils/auth";
import {ElTreeV2, FormInstance} from "element-plus";
import Edit from "@/model/edit";

const list = inject("list") as any
const edit = inject("edit", new Edit({}))
const auth = makeModelAuth("site.sitePackage")
const rules = {
    title:[{required:true, message:'必填'}],
    package_id: [{required:true, message:'必填'}],
}

const formRef = ref<FormInstance>()

const submit = () => {
    let url = list.currentRow ? auth.edit : auth.add
    edit.submit({
        formRef: formRef.value,
        url: "/" + url,
        list: list,
    })
}

onBeforeMount(() => {
    edit.init(async () => {

        if (list.currentRow) {
            // 请求表单数据
            let res = await simpleGet('/' + auth.edit, {id: list.currentRow.id})
            edit.info = res.info
        } else {
            edit.info = {
                status: 1,
            }
        }
    })
})

</script>

<style scoped>

</style>
